var app=sm("do_App");
var page=sm("do_Page");
var nf = sm("do_Notification");
var ListData = mm("do_ListData");
var config=require("config");
var cache=sm("do_DataCache");

var do_back=ui("do_back");
var do_ListView=ui("do_ListView");
var do_ALayout_root=ui("do_ALayout_root");

//用于等待登录的过程
do_ALayout_root.add("loadingUI", "source://view/loadingUI.ui", 0, 0);
var loadingUI = ui("loadingUI");
//初始化隐藏遮盖
loadingUI.visible = true;

page.on("back",function(){
	app.closePage();
});
do_back.on("touch",function(){
	app.closePage();
});
var userinfo=cache.loadData("userinfo");
page.on("loaded", function(data, e) {
	var nowdate=new Date();
	var olddate=nowdate.getTime();
	app.fire("tologin",{times:olddate,pagesize:2});
	var http = mm("do_Http");
	http.method = "POST";  
	http.timeout = 30000; 
	http.contentType = "application/json"; 
	http.url = config.baseUrl+"getCompanyList"; 
	http.body = JSON.stringify({businesstype:"",usernum:userinfo.usernum,userId:userinfo.userid}); 
	http.on("success", function(data) {
		loadingUI.visible = false;
		if(data.result==1 && data.data.length>0){	
			ListData.addData(data.data);
		    do_ListView.bindItems(ListData);
			ui("do_balanceTotal").text=parseFloat(data.data[0].balancetotal).toFixed(2)+"万元";
		}
		else if(data.result==3045){	
			 app.closePage({data:"帐号可能被其它终端登录，请重新登录", animationType:"", layer:2});	
			 cache.saveData("userinfo", "");
		}
		else{
			nf.toast(data.msg || "失败");
		}
	});
	http.on("fail", function(data) {
		loadingUI.visible = false;
		nf.toast(data.msg || "网络超时");
	});
	http.request();
});
page.on("result",function(result){
	var nowdate=new Date();
	var olddate=nowdate.getTime();
	app.fire("tologin",{times:olddate,pagesize:2});
});